package com.haiyou.common.spring.filter;


import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * 
 * @Description: http 过滤器配置类
 * @author xingyuan
 * @date 2022年8月22日 下午6:24:53
 */
@Configuration
public class FilterConfig {

	/**
	 * actuator 过滤器
	 * @return
	 */
	@Bean
	public FilterRegistrationBean<ActuatorFilter> initActuatorFilter() {
		
		FilterRegistrationBean<ActuatorFilter> filterRegistrationBean = 
				new FilterRegistrationBean<>();

		filterRegistrationBean.addUrlPatterns("/actuator/*");
		filterRegistrationBean.setFilter(new ActuatorFilter());
		filterRegistrationBean.setName("actuatorFilter");
		
		return filterRegistrationBean;
	}
	
	
	/**
	 * http api 
	 * @return
	 */
	@Bean
	public FilterRegistrationBean<ApiAccessFilter> initApiAccessFilter() {
		
		FilterRegistrationBean<ApiAccessFilter> filterRegistrationBean = 
				new FilterRegistrationBean<>();

		filterRegistrationBean.addUrlPatterns("/*");
		filterRegistrationBean.setFilter(new ApiAccessFilter());
		filterRegistrationBean.setName("apiAccessFilter");
		
		return filterRegistrationBean;
	}
	
}
